#pragma once

namespace mopenocd
{

class rttSerial
{
public:
    enum Direction
    {
        Input = 1,
        Output = 2,
        AllDirections = Input | Output
    };

public:
    rttSerial();
    ~rttSerial();

    bool open(const char *name);
    void close();
    bool waitForReadyRead(int ms = 200);
    bool waitForReadyWrite(int ms = 20);
    int read(void *buf, unsigned max);
    int readAll(void *buf, unsigned max, int timeout_ms = 20);
    int write(const void *buf, unsigned max);
    int writeAll(const void *buf, unsigned max, int timeout_ms = 20);
    bool setup(int br, int parity = 'N', int stopbits = 1);
    bool setBaudRate(int br);
    bool clear(enum Direction dir = AllDirections);
    int write(const char *data);

private:
    int fd;
};

}
